<?php
session_start();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "connectdb.php";
$username = $_SESSION['sess_Username'];
$password = $_SESSION['sess_Password'];

$user_type = $_POST["txtusertype"];  

$SQL_SELECT_COUNTDUP = "SELECT COUNT(user_type) FROM ag_usertype WHERE user_type = '$user_type' ;";
$DUPLICATE = mysql_query($SQL_SELECT_COUNTDUP);
$DUPLICATE_NUM = mysql_result($DUPLICATE,0); 

if($DUPLICATE_NUM == '0'){
	
		$SQL_SELECT_MAX = "SELECT MAX(user_typeid) FROM ag_usertype ;";
		$resultmax = mysql_query($SQL_SELECT_MAX);
		$resultmax2 = mysql_result($resultmax,0);
		$resultmax3 = $resultmax2+1;
	
		$SQL_INSERT_USERTYPE = "INSERT INTO ag_usertype VALUES('$resultmax3','$user_type');";
		$result = mysql_db_query($dbname,$SQL_INSERT_USERTYPE);
		
	if($result){
		?>
		<script>
		alert("เพิ่มรายการประเภทผู้ใช้เรียบร้อยแล้ว");
		</script>
        <meta http-equiv='refresh' content='0;URL=admin_usertype.php'>
		<?
	}
	else 
	{
		?>
		<script>
		alert("ผิดพลาด");
		history.back();
		</script>
		<?
	}
} 
else{
?>
<script>
alert("มีประเภทรายการนี้แล้วกรุณากรอกใหม่");
history.back();
</script>
<?
}
?>

